﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyHospital.BLL;

namespace MyHospital.web
{
    public partial class ManagerDepartment : System.Web.UI.Page
    {
        Department department = new Department();
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Button3_Click(object sender, EventArgs e)
        {
            if (Request.Form["myRadio"] == null)
            {
                Label1.Text = "没有选中项";
                jsLiteral.Text = "";
            }
            else
            {
                string value;
                value = Request.Form["myRadio"].ToString();
                jsLiteral.Text = "setNowRadio('" + value + "');";
                department.DeleteDepartment(GridView1.Rows[Convert.ToInt16(value)].Cells[0].Text);
                Label1.Text = GridView1.Rows[Convert.ToInt16(value)].Cells[0].Text + "号部门删除成功";
                GridView1.DataSourceID = "LinqDataSource1";
                GridView1.DataBind();
            }
        }
        protected void InsertSubmit(object sender, EventArgs e)
        {
            if (department.isDepartExit(txtName.Text.Trim()) == true)//科室不存在
            {
                department.InsertDepartment(txtName.Text, txtDec.Text);
                Label1.Text = "插入成功";
                GridView1.DataSourceID = "LinqDataSource1";
                GridView1.DataBind();
            }
            else Label1.Text = "科室已存在";
        }

        protected void SearcheDepartment(object sender, EventArgs e)
        {
            if (Page.IsPostBack)
            {
                if (department.isDepartExit(txtDepartmentName.Text.Trim()) == false)//科室存在
                {
                    GridView1.DataSourceID = null;
                    GridView1.DataBind();
                    var results = department.GetDepartmentsList(txtDepartmentName.Text);
                    GridView1.DataSource = results;
                    GridView1.DataBind();
                }
                else Label1.Text = "科室不存在";
            }
        }
        protected void SearchBack(object sender, EventArgs e)
        {
            GridView1.DataSourceID = "LinqDataSource1";
            GridView1.DataBind();
        }
    }
}